<?php
ob_start();
	include 'connect/connect.php';
	check_admin();
	include 'class/class.phieuthu.php';
$result2 = mysql_query('SELECT * FROM tbl_giangvien ') ;
?>
<head>

<link href="Calendar/CalendarControl.css"
      rel="stylesheet" type="text/css">
<script src="Calendar/CalendarControl.js"
        language="javascript"></script>

</head>
<form method ="POST" 	action=#>
	Chọn từ khóa:<select id="tukhoa" name="tukhoa">
		<option value=''>---------All--------</option>
	<?php
	while($row = mysql_fetch_array($result2))
	{
	echo '<option value='.$row['id'].'>'.$row['f_hovaten'].'</option>';
	
	}
	?>

	</select>
	Tập trung:
	<select id="taptrung" name="taptrung">
		<option value='0'>Không</option>
		<option value='1'>Có</option>
		
	</select>
	<p>T&#7915;: <input type="text" name="dau"  onfocus="showCalendarControl(this);"  value="<?php echo $_POST['dau']; ?>" size="14">Đến ngày
	ngày: <input type="text"  onfocus="showCalendarControl(this);"  name="cuoi" value="<?php echo $_POST['cuoi']; ?>" size="15">	
	<input type=submit value="TÌm kiếm">
</form>
<?php		
$dau = $_POST['dau'];
$dau = str_replace("/","-",$dau);
$cuoi = $_POST['cuoi'];
$cuoi = str_replace("/","-",$cuoi);
if($_POST['taptrung'] == 0)
{
				if ($dau!='' AND $cuoi!='')
				{

					$dau = strtotime($dau);
					$cuoi = strtotime($cuoi);

					
				$result = mysql_query("SELECT * FROM tbl_thuphieu  ORDER BY f_maphieu DESC") 
				or die(mysql_error());  
				$tukhoa = $_POST['tukhoa'];
				$tukhoa = mb_strtolower($tukhoa, 'UTF-8');
				$loaitimkiem = $_POST['loaitimkiem'];	
				$phieuthu = new phieuthu;

				if($tukhoa != '')
				{
					$result = mysql_query("SELECT * FROM tbl_thuphieu WHERE f_giangvien={$tukhoa}  ORDER BY f_maphieu DESC") ;	

				}
				else
				{
					$result = mysql_query("SELECT * FROM tbl_thuphieu  ORDER BY f_maphieu DESC") ;	
				}
					
							echo "<table border='1' style='border-collapse: collapse'>";
							echo   '<td width="59" bgcolor="#D6E0D8">Mã phiếu</td>
							<td width="75" bgcolor="#D6E0D8">Ngày bắt đầu</td>
							<td width="51" bgcolor="#D6E0D8">Tiền học phí</td>
							<td width="59" bgcolor="#D6E0D8">Tiền giảm thu</td>
							<td width="70" bgcolor="#D6E0D8">Tiền phụ thu</td>
							<td width="78" bgcolor="#D6E0D8">Tiền thực thu</td>
							<td width="98" bgcolor="#D6E0D8">Người tạo</td>
							<td width="87" bgcolor="#D6E0D8">Mã học viên</td>
							<td width="116" bgcolor="#D6E0D8">Họ và tên</td>
							<td bgcolor="#D6E0D8">Mã lớp</td>
							<td bgcolor="#D6E0D8">Trạng thái</td><td bgcolor="#D6E0D8">Khóa</td><td bgcolor="#D6E0D8">Giảng viên</td><td bgcolor="#D6E0D8">Hoa hồng</td><td bgcolor="#D6E0D8">Đính kèm</td><td bgcolor="#D6E0D8">Edit</td>';
							
				if($dau == $cuoi)
				{		
					
					while ($row = mysql_fetch_array($result))
					{
						$ngaytao = strtotime($row['f_ngaybatdau']);
						if(($ngaytao == $dau) AND ($ngaytao == $cuoi) )
						{		
							if(($row['f_khoa'] == 1) or ($row['f_khoa'] == 3))
							{
							  echo "<tr>";
							  echo "<td>" . $row['f_maphieu'] . "</td>";
							  echo "<td>" . "<a href='today.php?d=".$row['f_ngaybatdau'] . "'>".$row['f_ngaybatdau']."</a></td>";
							  echo "<td>" .   number_format($row['f_tienhp'])  . "</td>";
							  echo "<td>" .  number_format($row['f_tiengt']) . "</td>";
							  echo "<td>" . number_format( $row['f_tiencd']) . "</td>";			  
							  echo "<td>" .  number_format($row['f_thucthu']) . "</td>";
							  echo "<td>" . $row['f_nguoitao'] . "</td>";
							  echo "<td>" . $row['f_mahocvien'] . "</td>";
							  echo "<td>" . $row['f_hovaten'] . "</td>";
							  echo "<td>" . $row['f_lop'] . "</td>";			  
							  echo "<td>" .$phieuthu->trang_thai($row['f_trangthai']) . "</td>";echo "<td>" .$phieuthu-> khoa ($row['f_khoa']) . "</td>";echo "<td>" .$row['f_tengiangvien'] .  "</td>";echo "<td>" .$row['f_hoahong'] .  "</td>";echo "<td><a href='" .$row['file'] .  "'>Link</a></td>";echo "<td> <a href='edit.php?stt=".$row['f_maphieu'] ."'>E</a></td>";		
							  echo "</tr>";
							 }
						}
					}
				}
				else
				{			
					while ($row = mysql_fetch_array($result))
					{
						$ngaytao = strtotime($row['f_ngaybatdau']);
						if(($ngaytao >= $dau) AND ($ngaytao <= $cuoi) )
						{		
							if(($row['f_khoa'] == 1) or ($row['f_khoa'] == 3))
							{
							  echo "<tr>";
							  echo "<td>" . $row['f_maphieu'] . "</td>";
							  echo "<td>" . "<a href='today.php?d=".$row[''] . "'>".$row['f_ngaybatdau']."</a></td>";
							  echo "<td>" .   number_format($row['f_tienhp'])  . "</td>";
							  echo "<td>" .  number_format($row['f_tiengt']) . "</td>";
							  echo "<td>" . number_format( $row['f_tiencd']) . "</td>";			  
							  echo "<td>" .  number_format($row['f_thucthu']) . "</td>";
							  echo "<td>" . $row['f_nguoitao'] . "</td>";
							  echo "<td>" . $row['f_mahocvien'] . "</td>";
							  echo "<td>" . $row['f_hovaten'] . "</td>";
							  echo "<td>" . $row['f_lop'] . "</td>";			  
							  echo "<td>" .$phieuthu->trang_thai($row['f_trangthai']) . "</td>";echo "<td>" .$phieuthu-> khoa ($row['f_khoa']) . "</td>";echo "<td>" .$row['f_tengiangvien'] .  "</td>";echo "<td>" .$row['f_hoahong'] .  "</td>";echo "<td><a href='" .$row['file'] .  "'>Link</a></td>";echo "<td> <a href='edit.php?stt=".$row['f_maphieu'] ."'>E</a></td>";		
							  echo "</tr>";
							 }
						}
					}
				}	
				echo "</table>";

					

				echo "<p>";
				echo 'Tổng số tiền học phí là: '.  number_format($sotien) ;
				}
				else
				{
					$dau = strtotime($dau);
					$cuoi = strtotime($cuoi);
				$result = mysql_query("SELECT * FROM tbl_thuphieu  ORDER BY f_maphieu DESC") 
				or die(mysql_error());  
				$tukhoa = $_POST['tukhoa'];
				$loaitimkiem = $_POST['loaitimkiem'];	
				$phieuthu = new phieuthu;
				if($tukhoa != '' )
				{
					$result = mysql_query("SELECT * FROM tbl_thuphieu WHERE f_giangvien = {$tukhoa} ORDER BY f_maphieu DESC") ;	
				}	
				else
				{
					$result = mysql_query("SELECT * FROM tbl_thuphieu  ORDER BY f_maphieu DESC") ;	
				}	
					echo "<table border='0'>";
					echo   '<td width="59" bgcolor="#D6E0D8">Mã phiếu</td>
							<td width="75" bgcolor="#D6E0D8">Ngày bắt đầu</td>
							<td width="51" bgcolor="#D6E0D8">Tiền học phí</td>
							<td width="59" bgcolor="#D6E0D8">Tiền giảm thu</td>
							<td width="70" bgcolor="#D6E0D8">Tiền phụ thu</td>
							<td width="78" bgcolor="#D6E0D8">Tiền thực thu</td>
							<td width="98" bgcolor="#D6E0D8">Người tạo</td>
							<td width="87" bgcolor="#D6E0D8">Mã học viên</td>
							<td width="116" bgcolor="#D6E0D8">Họ và tên</td>
							<td bgcolor="#D6E0D8">Mã lớp</td>
							<td bgcolor="#D6E0D8">Trạng thái</td><td bgcolor="#D6E0D8">Khóa</td><td bgcolor="#D6E0D8">Giảng viên</td><td bgcolor="#D6E0D8">Hoa hồng</td><td bgcolor="#D6E0D8">Đính kèm</td><td bgcolor="#D6E0D8">E</td>';
					while ($row = mysql_fetch_array($result))
					{

							if(($row['f_khoa'] == 1) or ($row['f_khoa'] == 3))
							{
							  echo "<tr>";
							  echo "<td>" . $row['f_maphieu'] . "</td>";
							  echo "<td>" . "<a href='today.php?d=".$row['f_ngaybatdau'] . "'>".$row['f_ngaybatdau']."</a></td>";
							  echo "<td>" .   number_format($row['f_tienhp'])  . "</td>";
							  echo "<td>" .  number_format($row['f_tiengt']) . "</td>";
							  echo "<td>" . number_format( $row['f_tiencd']) . "</td>";			  
							  echo "<td>" .  number_format($row['f_thucthu']) . "</td>";
							  echo "<td>" . $row['f_nguoitao'] . "</td>";
										  $sotien = $sotien + $row['f_thucthu'];			  
							  echo "<td>" . $row['f_mahocvien'] . "</td>";
							  echo "<td>" . $row['f_hovaten'] . "</td>";
							  echo "<td>" . $row['f_lop'] . "</td>";			  
							  echo "<td>" .$phieuthu->trang_thai($row['f_trangthai']) . "</td>";echo "<td>" .$phieuthu-> khoa ($row['f_khoa']) . "</td>";echo "<td>" .$row['f_tengiangvien'] .  "</td>";echo "<td>" .$row['f_hoahong'] .  "</td>";echo "<td><a href='" .$row['file'] .  "'>Link</a></td>";echo "<td> <a href='edit.php?stt=".$row['f_maphieu'] ."'>E</a></td>";		
							  echo "</tr>";
							}
					}

				echo "</table>";
				echo "<p>";
				echo 'Tổng số tiền học phí là: '.  number_format($sotien) ;
				}
}
else
{
			if ($dau!='' AND $cuoi!='')
				{

					$dau = strtotime($dau);
					$cuoi = strtotime($cuoi);

					
				$result = mysql_query("SELECT * FROM tbl_thuphieu WHERE  f_khoa = 2  ORDER BY f_maphieu DESC") 
				or die(mysql_error());  
				$tukhoa = $_POST['tukhoa'];
				$tukhoa = mb_strtolower($tukhoa, 'UTF-8');
				$loaitimkiem = $_POST['loaitimkiem'];	
				$phieuthu = new phieuthu;
				
				if($tukhoa != '')
				{
					$result = mysql_query("SELECT * FROM tbl_thuphieu WHERE f_khoa = 2 and f_giangvien={$tukhoa}  ORDER BY f_maphieu DESC") ;	
					
					echo $tukhoa;echo'-123';
				}
				else
				{
					$result = mysql_query("SELECT * FROM tbl_thuphieu WHERE  f_khoa = 2 ORDER BY f_maphieu DESC") ;	
				}
					
							echo "<table border='1' style='border-collapse: collapse'>";
							echo   '<td width="59" bgcolor="#D6E0D8">Mã phiếu</td>
							<td width="75" bgcolor="#D6E0D8">Ngày bắt đầu</td>
							<td width="51" bgcolor="#D6E0D8">Tiền học phí</td>
							<td width="59" bgcolor="#D6E0D8">Tiền giảm thu</td>
							<td width="70" bgcolor="#D6E0D8">Tiền phụ thu</td>
							<td width="78" bgcolor="#D6E0D8">Tiền thực thu</td>
							<td width="98" bgcolor="#D6E0D8">Người tạo</td>
							<td width="87" bgcolor="#D6E0D8">Mã học viên</td>
							<td width="116" bgcolor="#D6E0D8">Họ và tên</td>
							<td bgcolor="#D6E0D8">Mã lớp</td>
							<td bgcolor="#D6E0D8">Trạng thái</td><td bgcolor="#D6E0D8">Khóa</td><td bgcolor="#D6E0D8">Giảng viên</td><td bgcolor="#D6E0D8">Hoa hồng</td><td bgcolor="#D6E0D8">Đính kèm</td><td bgcolor="#D6E0D8">Edit</td>';
							
				if($dau == $cuoi)
				{	
					
					while ($row = mysql_fetch_array($result))
					{
					
						$ngaytao = strtotime($row['f_ngaybatdau']);
						if(($ngaytao == $dau) AND ($ngaytao == $cuoi) )
						{		

							  echo "<tr>";
							  echo "<td>" . $row['f_maphieu'] . "</td>";
							  echo "<td>" . "<a href='today.php?d=".$row['f_ngaybatdau'] . "'>".$row['f_ngaybatdau']."</a></td>";
							  echo "<td>" .   number_format($row['f_tienhp'])  . "</td>";
							  echo "<td>" .  number_format($row['f_tiengt']) . "</td>";
							  echo "<td>" . number_format( $row['f_tiencd']) . "</td>";			  
							  echo "<td>" .  number_format($row['f_thucthu']) . "</td>";
							  echo "<td>" . $row['f_nguoitao'] . "</td>";
							  echo "<td>" . $row['f_mahocvien'] . "</td>";
							  echo "<td>" . $row['f_hovaten'] . "</td>";
							  echo "<td>" . $row['f_lop'] . "</td>";			  
							  echo "<td>" .$phieuthu->trang_thai($row['f_trangthai']) . "</td>";echo "<td>" .$phieuthu-> khoa ($row['f_khoa']) . "</td>";echo "<td>" .$row['f_tengiangvien'] .  "</td>";echo "<td>" .$row['f_hoahong'] .  "</td>";echo "<td><a href='" .$row['file'] .  "'>Link</a></td>";echo "<td> <a href='edit.php?stt=".$row['f_maphieu'] ."'>E</a></td>";		
							  echo "</tr>";
							 
						}
					}
				}
				else
				{
					while ($row = mysql_fetch_array($result))
					{	
						$ngaytao = strtotime($row['f_ngaybatdau']);
						if(($ngaytao >= $dau) AND ($ngaytao <= $cuoi) )
						{		
							
							  echo "<tr>";
							  echo "<td>" . $row['f_maphieu'] . "</td>";
							  echo "<td>" . "<a href='today.php?d=".$row['f_ngaybatdau'] . "'>".$row['f_ngaybatdau']."</a></td>";
							  echo "<td>" .   number_format($row['f_tienhp'])  . "</td>";
							  echo "<td>" .  number_format($row['f_tiengt']) . "</td>";
							  echo "<td>" . number_format( $row['f_tiencd']) . "</td>";			  
							  echo "<td>" .  number_format($row['f_thucthu']) . "</td>";
							  echo "<td>" . $row['f_nguoitao'] . "</td>";
							  echo "<td>" . $row['f_mahocvien'] . "</td>";
							  echo "<td>" . $row['f_hovaten'] . "</td>";
							  echo "<td>" . $row['f_lop'] . "</td>";			  
							  echo "<td>" .$phieuthu->trang_thai($row['f_trangthai']) . "</td>";echo "<td>" .$phieuthu-> khoa ($row['f_khoa']) . "</td>";echo "<td>" .$row['f_tengiangvien'] .  "</td>";echo "<td>" .$row['f_hoahong'] .  "</td>";echo "<td><a href='" .$row['file'] .  "'>Link</a></td>";echo "<td> <a href='edit.php?stt=".$row['f_maphieu'] ."'>E</a></td>";		
							  echo "</tr>";
							 
						}
					}
				}	
				echo "</table>";

					

				echo "<p>";
				echo 'Tổng số tiền học phí là: '.  number_format($sotien) ;
				}
				else
				{
					$dau = strtotime($dau);
					$cuoi = strtotime($cuoi);
				$result = mysql_query("SELECT * FROM tbl_thuphieu WHERE  f_khoa = 2  ORDER BY f_maphieu DESC") 
				or die(mysql_error());  
				$tukhoa = $_POST['tukhoa'];
				$loaitimkiem = $_POST['loaitimkiem'];	
				$phieuthu = new phieuthu;
				if($tukhoa != '' )
				{
					$result = mysql_query("SELECT * FROM tbl_thuphieu WHERE  f_khoa = 2 and f_giangvien = {$tukhoa} ORDER BY f_maphieu DESC") ;	
				}	
				else
				{
					$result = mysql_query("SELECT * FROM tbl_thuphieu WHERE  f_khoa = 2  ORDER BY f_maphieu DESC") ;	
				}	
					echo "<table border='0'>";
					echo   '<td width="59" bgcolor="#D6E0D8">Mã phiếu</td>
							<td width="75" bgcolor="#D6E0D8">Ngày bắt đầu</td>
							<td width="51" bgcolor="#D6E0D8">Tiền học phí</td>
							<td width="59" bgcolor="#D6E0D8">Tiền giảm thu</td>
							<td width="70" bgcolor="#D6E0D8">Tiền phụ thu</td>
							<td width="78" bgcolor="#D6E0D8">Tiền thực thu</td>
							<td width="98" bgcolor="#D6E0D8">Người tạo</td>
							<td width="87" bgcolor="#D6E0D8">Mã học viên</td>
							<td width="116" bgcolor="#D6E0D8">Họ và tên</td>
							<td bgcolor="#D6E0D8">Mã lớp</td>
							<td bgcolor="#D6E0D8">Trạng thái</td><td bgcolor="#D6E0D8">Khóa</td><td bgcolor="#D6E0D8">Giảng viên</td><td bgcolor="#D6E0D8">Hoa hồng</td><td bgcolor="#D6E0D8">Đính kèm</td><td bgcolor="#D6E0D8">E</td>';
					while ($row = mysql_fetch_array($result))
					{

							
							  echo "<tr>";
							  echo "<td>" . $row['f_maphieu'] . "</td>";
							  echo "<td>" . "<a href='today.php?d=".$row['f_ngaybatdau'] . "'>".$row['f_ngaybatdau']."</a></td>";
							  echo "<td>" .   number_format($row['f_tienhp'])  . "</td>";
							  echo "<td>" .  number_format($row['f_tiengt']) . "</td>";
							  echo "<td>" . number_format( $row['f_tiencd']) . "</td>";			  
							  echo "<td>" .  number_format($row['f_thucthu']) . "</td>";
							  echo "<td>" . $row['f_nguoitao'] . "</td>";
										  $sotien = $sotien + $row['f_thucthu'];			  
							  echo "<td>" . $row['f_mahocvien'] . "</td>";
							  echo "<td>" . $row['f_hovaten'] . "</td>";
							  echo "<td>" . $row['f_lop'] . "</td>";			  
							  echo "<td>" .$phieuthu->trang_thai($row['f_trangthai']) . "</td>";echo "<td>" .$phieuthu-> khoa ($row['f_khoa']) . "</td>";echo "<td>" .$row['f_tengiangvien'] .  "</td>";echo "<td>" .$row['f_hoahong'] .  "</td>";echo "<td><a href='" .$row['file'] .  "'>Link</a></td>";echo "<td> <a href='edit.php?stt=".$row['f_maphieu'] ."'>E</a></td>";		
							  echo "</tr>";
							
					}

				echo "</table>";
				echo "<p>";
				echo 'Tổng số tiền học phí là: '.  number_format($sotien) ;
				}
				
		
}

?>